 /********************************************************************
 
 Copyright (C), 2012年 dhc. All rights reserved.
 
 Filename: 	    NavigationMainViewController.m
 
 Author:        muzongcun
 
 Version:       1.0
 
 Description:   邮件功能主界面
 
 History:
 
 muzongcun    2012/3/10     1.0     Create
 
 ********************************************************************/

#import "NavigationMainViewController.h"
#import "AppDelegate.h"
#import "MailListCell.h"
#import "Session.h"
#import "XmlRpc.h"
#define MenuWidth               160         //切换为半屏的宽度
#define FullScreenTVFrame       CGRectMake(0, 0, 320, 416)

@implementation NavigationMainViewController

@synthesize     m_nav;
@synthesize     m_navBar;
@synthesize     m_boxType;
@synthesize     m_mailList;
@synthesize     m_tableView;
@synthesize     m_strEmployeeID;
@synthesize     m_bStafferClient;
@synthesize     m_ClientSwittchName;
@synthesize     m_receiveMailNum;
#pragma mark - Lifecycle

-(id) initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
	if(self)
	{
        m_stafferSwitchID   = @"";   
        m_ClientSwittchID   = @"";  
        m_ClientSwittchName = @"";
        m_stafferSwitchName = @""; 
        m_postionName       = @"";
         
        m_stafferSwitchBut = nil;
        m_clientSwitchBut  = nil;
        m_strPositonName   = [[NSString alloc]init];
        
        //默认是业务员tab选中
        m_bStafferClient = YES;
        m_bStretch       = NO;
        
        //初始化邮箱类型为收件箱
        m_boxType = RECEIVE_BOX;
    }    
    return self;    
}
//******************************************************
// Method:     initWithOwner
// Access:     public 
// Returns:    void
// Parameter:  
// Note:	   top bar create
// Author      muzongcun  2012/03/12 create
//*******************************************************
- (id)initWithOwner:(UIViewController *)owner
{
    UIButton *playNowButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 20, 20, 40)];
    playNowButton.titleLabel.text=@"";
    // [playNowButton setBackgroundImage:[UIImage imageNamed:@"right.png"] forState:UIControlStateNormal];
    
    [playNowButton addTarget:self action:@selector(AgoList) forControlEvents:UIControlEventTouchDown];
    
    UIBarButtonItem *bar =[[UIBarButtonItem alloc] initWithCustomView:playNowButton];
    
    [playNowButton release];
    
    return (id)bar;
}

- (void)viewWillAppear:(BOOL)animated
{
    //计算－－－发送，已经发送箱，草稿箱的未读邮件数量
    
    UIFont *font       = [UIFont systemFontOfSize:14];
    
    //职位名字
    NSString* posName = [[Session share] getMemberPosiName];
    //计算文本内容的高度和宽度
    CGSize size = [posName sizeWithFont:font constrainedToSize:CGSizeMake(310.0f, 2000.0f) lineBreakMode:  UILineBreakModeCharacterWrap];
    
    m_oneSelfBtn.frame = CGRectMake(10.0, 7.0, size.width, 30.0);

    //添加一个空格
    NSString* strPosName = [NSString stringWithFormat:@" %@",posName];
    [m_oneSelfBtn setTitle:strPosName forState:UIControlStateNormal];
    UIFont *font1          = [UIFont systemFontOfSize:10];
    m_oneSelfBtn.titleLabel.font = font1;


    
    if ([m_strPositonName compare:posName] != 0) 
    {
        [m_strPositonName release];
        m_strPositonName = [[NSString alloc]initWithFormat:@"%@",[[Session share] getMemberPosiName]];
        m_stafferClientInfo = [[NSString alloc] initWithFormat:@"%@:%@",m_strPositonName,[[Session share] getMemberNickName]];
    }
    
    //修改登陆人职位名字
    m_LoginName.text = [[Session share] getMemberPosiName];
    
    //改变角色是时候，tap图片需要重新设置
    [self SetTabImage:m_bStafferClient];
    
    //刷新navigationmainview
    [m_tableView reloadData];
}

- (void)viewDidAppear:(BOOL)animated
{

    //[self onReceive];
}
//******************************************************
// Method:     viewDidLoad
// Access:     public 
// Returns:    void
// Parameter:  
// Note:	   
// Author      muzongcun  2012/03/12 create
//*******************************************************
- (void)viewDidLoad 
{
    [super viewDidLoad];
    
    m_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0.0, 44.0, 320.0, 480-20-44-49) style:UITableViewStylePlain];
	m_tableView.delegate = self;
	m_tableView.dataSource = self;
    m_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    
    CGRect  tempFrame = { 0 };
    
    //得到maillist的地址
    m_mailList = [[MailList alloc] initWithNibName: @"MailList" bundle: nil];
    m_nav = [[NavigationViewController alloc] initWithRootViewController: m_mailList];
    
    //调整界面高度
    tempFrame = m_nav.view.frame ;
    tempFrame.size.height -= 20;
    m_nav.view.frame = tempFrame;
    
    //保存当前的控件到appdelegate
    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    [appDelegate setMainViewCtl:self];
    
    //设置事件代理
    m_nav.motionDelegate = self;
    [m_nav setNavigationBarHidden: NO animated:YES];

    //保存客户区的大小
    m_contentBaseFrame = m_mailList.view.frame;
    m_contentBaseFrame.size.height = 480-20-49;   //客户区减去top和bottom的高度
    
    //添加最上面的navigation Bar
    UIBarButtonItem* naviBut = [[UIBarButtonItem alloc] initWithTitle:@"导航" style:(UIBarButtonItemStylePlain) target:self action:@selector(onNavigation)];
    self.navigationItem.leftBarButtonItem = naviBut;
    [naviBut release];
    
    //导航栏生成
    m_topnavBar = [[UINavigationBar alloc]init];
    m_topnavBar.frame = CGRectMake(0, 0, 320, 44);
    
    //快速切换到自身的按钮
    UIFont *font          = [UIFont systemFontOfSize:14];
    NSString* posName = [[Session share] getMemberPosiName];
    //计算文本内容的高度和宽度
    CGSize size = [posName sizeWithFont:font constrainedToSize:CGSizeMake(310.0f, 2000.0f) lineBreakMode:  UILineBreakModeCharacterWrap];

    m_oneSelfBtn = [[UIButton alloc] initWithFrame:CGRectMake(10.0, 7.0, size.width, 30.0)];
    
    UIImage *buttonImageNormal  = nil;
    UIImage *buttonImagePressed = nil;
    
    NSString* devVersion = [[UIDevice currentDevice] systemVersion];
    if ([devVersion compare:@"4.3.3"] == 0)
    {
        buttonImageNormal = [UIImage imageNamed:PIC_MAIL_SWITCH_SELF_NORMAL];
        buttonImagePressed = [UIImage imageNamed:PIC_MAIL_SWITCH_SELF_PRESS];
    }else
    {
        buttonImageNormal  = [[UIImage imageNamed:PIC_MAIL_SWITCH_SELF_NORMAL] resizableImageWithCapInsets:UIEdgeInsetsMake(15, 15, 15, 40)];
        buttonImagePressed = [[UIImage imageNamed:PIC_MAIL_SWITCH_SELF_PRESS] resizableImageWithCapInsets:UIEdgeInsetsMake(15, 15, 15, 40)]; 
    }

    [m_oneSelfBtn setBackgroundImage:buttonImageNormal forState:UIControlStateNormal];
    
    [m_oneSelfBtn setBackgroundImage:buttonImagePressed forState:UIControlStateHighlighted];
    NSString* strPosName = [NSString stringWithFormat:@" %@",posName]; 
    [m_oneSelfBtn setTitle:strPosName forState:UIControlStateNormal];
    

    UIFont *font1          = [UIFont systemFontOfSize:10];
    m_oneSelfBtn.titleLabel.font = font1;
    [m_oneSelfBtn setTitleColor: [UIColor whiteColor]forState:UIControlStateNormal];
    [m_oneSelfBtn addTarget:self action:@selector(onSwitchOneSelf) forControlEvents:UIControlEventTouchUpInside];
    

    //存放标签的view
    UIView* butContainerView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
    
    //添加切换到自身的按钮
    [butContainerView addSubview:m_oneSelfBtn];
    //[m_stafferNameTitle release];
    
     //设置导航栏背景为黑色
    UIImage* imageBar = [UIImage imageNamed:PIC_MAIL_TOP_BAR];
    
    if ([devVersion compare:@"4.3.3"] == 0)
    {
        [m_topnavBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)];
        [m_topnavBar setTintColor:NAVIGATION_BAR_COLOR];
    }else
    {
        [m_topnavBar setBackgroundImage:imageBar forBarMetrics:UIBarMetricsDefault];
    }
    //把存放客户和业务员的view放到导航栏上
    [m_topnavBar addSubview:butContainerView];
    [butContainerView release];
    
    [self.view addSubview:m_tableView];
    [self.view addSubview:m_topnavBar];
    [self.view addSubview:m_nav.view];
    
    //保存职位名字和个人名字
    m_postionName = [[NSString alloc]initWithFormat:@"%@", [[Session share]getMemberPosiName]];
    m_stafferSwitchName = [[Session share]getMemberNickName]; 
    /*table view cell控件描画*/
    /************************************************************************/
    
    //业务员tab按钮
    m_stafferSwitchBut = [[UIButton alloc] initWithFrame:CGRectMake(0.0, 0.0, 80.0, 44.0)];
    [m_stafferSwitchBut setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
#ifdef _CREATE_LABEL  
    //增加tab上的业务员label的名字
    m_tabStafferTiltle = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 80.0, 44.0)];
    m_tabStafferTiltle.text = @"   业务员";
    [m_tabStafferTiltle setBackgroundColor:[UIColor clearColor]];
    m_tabStafferTiltle.textColor = [UIColor whiteColor];
    [m_stafferSwitchBut addSubview:m_tabStafferTiltle];
#else
    [m_stafferSwitchBut setTitle:@"业务员" forState:UIControlStateNormal];
#endif
    //背景图片设置
    UIImage *switchBtnImageNormal = [UIImage imageNamed:PIC_MAIL_SWITCH_TAB_NORMAL];
    [m_stafferSwitchBut setBackgroundImage:switchBtnImageNormal forState:UIControlStateNormal];
    
    UIImage *switchBtnImagePressed = [UIImage imageNamed:PIC_MAIL_SWITCH_TAB_STAFFER_PRESS];
    [m_stafferSwitchBut setBackgroundImage:switchBtnImagePressed forState:UIControlStateHighlighted];
    
    [m_stafferSwitchBut addTarget:self action:@selector(onStafferTabSwitch) forControlEvents:UIControlEventTouchUpInside];
    
    //客户tab按钮
    m_clientSwitchBut = [[UIButton alloc] initWithFrame:CGRectMake(80.0, 0.0, 220.0, 44.0)];
    [m_clientSwitchBut setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
#ifdef _CREATE_LABEL 
    //增加tab上的客户label的名字
    m_tabClientTiltle = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 80.0, 44.0)];
    m_tabClientTiltle.text = @"     客户";
    [m_tabClientTiltle setBackgroundColor:[UIColor clearColor]];
    m_tabClientTiltle.textColor = [UIColor whiteColor];
    [m_clientSwitchBut addSubview:m_tabClientTiltle];
#else
    [m_clientSwitchBut setTitle:@"     客户" forState:UIControlStateNormal];
#endif
    //背景图片设置
    //switchBtnImageNormal = [[UIImage imageNamed:PIC_MAIL_SWITCH_TAB_NORMAL] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 0, 20, 44)];
    
    switchBtnImageNormal = [UIImage imageNamed:PIC_MAIL_SWITCH_TAB_NORMAL];
    [m_clientSwitchBut setBackgroundImage:switchBtnImageNormal forState:UIControlStateNormal];
    
    switchBtnImagePressed = [UIImage imageNamed:PIC_MAIL_SWITCH_TAB_CLIENT_PRESS];
    //switchBtnImagePressed = [[UIImage imageNamed:PIC_MAIL_SWITCH_TAB_CLIENT_PRESS] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 0, 20, 44)];
    
    [m_clientSwitchBut setBackgroundImage:switchBtnImagePressed forState:UIControlStateHighlighted];
    
    [m_clientSwitchBut addTarget:self action:@selector(onClientTabSwitch) forControlEvents:UIControlEventTouchUpInside];
    
    //设置选中的tab的颜色
    [m_stafferSwitchBut setTitleColor:[UIColor colorWithRed:56/255.0 green:191/255.0 blue:255/255.0 alpha:1.0] forState:UIControlStateNormal]; 
    [m_clientSwitchBut setTitleColor:[UIColor colorWithRed:1 green:1 blue:1 alpha:1.0] forState:UIControlStateNormal]; 
    
    //选择不同的tap，
    //切换不同业务员，客户职位名字的名字
    m_stafferNameTitle = [[UILabel alloc] initWithFrame:CGRectMake(5.0, 6.0, 320.0, 15.0)];
    
    m_stafferNameTitle.text = [[Session share] getMemberPosiName];;
    m_stafferNameTitle.font = [UIFont systemFontOfSize:12];
    [m_stafferNameTitle setBackgroundColor:[UIColor  clearColor]];
    m_stafferNameTitle.textColor = [UIColor whiteColor];
    
    //业务员，客户的名字
    m_stafferName = [[UILabel alloc] initWithFrame:CGRectMake(5.0, 24.0, 100.0, 15.0)];
    m_stafferName.text = [[Session share]getMemberNickName];
    m_stafferName.font = [UIFont systemFontOfSize:12];
    [m_stafferName setBackgroundColor:[UIColor  clearColor]];
    m_stafferName.textColor = [UIColor whiteColor];
    

    
    //显示业务员，客户人员列表
    m_switchBut = [[UIButton alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
    switchBtnImageNormal = [UIImage imageNamed:PIC_MAIL_SWITCH_BUT_BG];
    [m_switchBut setBackgroundImage:switchBtnImageNormal forState:UIControlStateNormal];
    switchBtnImagePressed = [UIImage imageNamed:PIC_MAIL_SWITCH_BUT_BG];
    [m_switchBut setBackgroundImage:switchBtnImagePressed forState:UIControlStateHighlighted];
    
    //显示业务员，客户人员列表
    m_stafferClientSwitchBut = [[UIButton alloc] initWithFrame:CGRectMake(100.0, 5.0, 50.0, 35.0)];
    [m_stafferClientSwitchBut setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [m_stafferClientSwitchBut setTitle:@"" forState:UIControlStateNormal];
    [m_stafferClientSwitchBut addTarget:self action:@selector(onStafferClientSwitch) forControlEvents:UIControlEventTouchUpInside];
    switchBtnImageNormal = [UIImage imageNamed:PIC_MAIL_CHANGE_BTN_NORMAL];
    [m_stafferClientSwitchBut setBackgroundImage:switchBtnImageNormal forState:UIControlStateNormal];
    switchBtnImagePressed = [UIImage imageNamed:PIC_MAIL_CHANGE_BTN_PRESS];
    [m_stafferClientSwitchBut setBackgroundImage:switchBtnImagePressed forState:UIControlStateHighlighted];
    
    
    //树型折叠图片（L）
    m_waitSendAngleArrowView  = [[UIImageView alloc] initWithFrame:CGRectMake(15.0, 15.0, 13.0, 12.0)];
    UIImage* mailAngleArrow = [UIImage imageNamed:PIC_MAIL_TREE_NODE];
    [m_waitSendAngleArrowView setImage:mailAngleArrow];
    [m_waitSendAngleArrowView setBackgroundColor:[UIColor clearColor]];
    
    //树型折叠图片（L）
    m_waitEvaluteAngleArrowView  = [[UIImageView alloc] initWithFrame:CGRectMake(15.0, 15.0, 13.0, 12.0)];
    
    [m_waitEvaluteAngleArrowView setImage:mailAngleArrow];
    [m_waitEvaluteAngleArrowView setBackgroundColor:[UIColor clearColor]];
    
    //树型折叠图片（L）
    m_withdrawAngleArrowView  = [[UIImageView alloc] initWithFrame:CGRectMake(15.0, 15.0, 13.0, 12.0)];
    
    //树型正常图片
    UIImage* mailImageNormal = [UIImage imageNamed:PIC_MAIL_TREE_MINUS];
    m_mailTreeImageViewNormal = [[UIImageView alloc] initWithFrame:CGRectMake(7.0, 15.0, 14.0, 14.0)];
    [m_mailTreeImageViewNormal setImage:mailImageNormal];
    [m_mailTreeImageViewNormal setBackgroundColor:[UIColor clearColor]];
    
    //树型展开图片
    UIImage* mailImagePress = [UIImage imageNamed:PIC_MAIL_TREE_PLUS];
    m_mailTreeImageViewPress = [[UIImageView alloc] initWithFrame:CGRectMake(7.0, 15.0, 14.0, 14.0)];
    [m_mailTreeImageViewPress setImage:mailImagePress];
    [m_mailTreeImageViewPress setBackgroundColor:[UIColor clearColor]];

    [m_withdrawAngleArrowView setImage:mailAngleArrow];
    [m_withdrawAngleArrowView setBackgroundColor:[UIColor clearColor]];
    

    //发送邮箱未读邮件的view
    m_sendMailNumImageView = [[UIImageView alloc] initWithFrame:CGRectMake(75.0, 10.0, 25.0, 22.0)];
    UIImage* mailNumImage = [UIImage imageNamed:PIC_MAIL_UNREAD_NUM];
    [m_sendMailNumImageView setImage:mailNumImage];
    [m_sendMailNumImageView setBackgroundColor:[UIColor clearColor]];
    
    //显示业务员，客户的的背景
    m_ImageView = [[[UIImageView alloc] initWithFrame:CGRectMake(0.0, 00.0, 320.0, 44.0)] autorelease];
    UIImage* Image = [UIImage imageNamed:PIC_MAIL_MENU_NORMAL];
    [m_ImageView setImage:Image];
    [m_ImageView setBackgroundColor:[UIColor clearColor]];
    
    //按钮图片
    m_btnImageNormal = [UIImage imageNamed:PIC_MAIL_MENU_NORMAL];
    m_btnImagePress = [UIImage imageNamed:PIC_MAIL_MENU_PRESS];
    
    //接收邮件button
    m_receiveBut = [[UIButton alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
    [m_receiveBut setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [m_receiveBut setTitle:@" 收件箱" forState:UIControlStateNormal];
    [m_receiveBut setBackgroundImage:m_btnImageNormal forState:UIControlStateNormal];
    [m_receiveBut setBackgroundImage:m_btnImagePress forState:UIControlStateHighlighted];
    [m_receiveBut addTarget:self action:@selector(onReceive) forControlEvents:UIControlEventTouchUpInside];
    
    //接收箱数量
    m_receiveMailNum = [[UILabel alloc] initWithFrame:CGRectMake(80.0, 10.0, 60.0, 22.0)];
    m_receiveMailNum.font = [UIFont systemFontOfSize:18];
    m_receiveMailNum.textAlignment = UITextAlignmentCenter;
    [m_receiveMailNum setBackgroundColor:[UIColor  clearColor]];
    
    //设置文字颜色
    m_receiveMailNum.textColor = [UIColor colorWithRed:56/255.0 green:191/255.0 blue:255/255.0 alpha:1.0];
    [m_receiveMailNum setText:@""];
    m_receiveMailNum.superview.hidden = YES;
    
    //发送邮件数量
    m_sendMailNum = [[UILabel alloc] initWithFrame:CGRectMake(8.0, 2.0, 18.0, 18.0)];
    m_sendMailNum.font = [UIFont systemFontOfSize:12];
    [m_sendMailNum setBackgroundColor:[UIColor  clearColor]];
    m_sendMailNum.textColor = [UIColor whiteColor];
    [m_sendMailNum setText:@"12"];
    
    //发送箱
    m_sendBut = [[UIButton alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
    [m_sendBut setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [m_sendBut setTitle:@"        发件箱" forState:UIControlStateNormal];
    //快速切换到自身的按钮
    [m_sendBut setBackgroundImage:m_btnImageNormal forState:UIControlStateNormal];
    [m_sendBut setBackgroundImage:m_btnImageNormal forState:UIControlStateHighlighted];
    
    [m_sendBut addTarget:self action:@selector(onSend) forControlEvents:UIControlEventTouchUpInside];
    
    //客户发送箱
    m_clientSendBut = [[UIButton alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
    [m_clientSendBut setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [m_clientSendBut setTitle:@" 发送箱" forState:UIControlStateNormal];
    //快速切换到自身的按钮
    
    [m_clientSendBut setBackgroundImage:m_btnImageNormal forState:UIControlStateNormal];
    [m_clientSendBut setBackgroundImage:m_btnImagePress forState:UIControlStateHighlighted];
    
    [m_clientSendBut addTarget:self action:@selector(onClientSend) forControlEvents:UIControlEventTouchUpInside];
    
    //待发箱
    m_waitSendBut = [[UIButton alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
    [m_waitSendBut setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [m_waitSendBut setTitle:@"       待发箱" forState:UIControlStateNormal];
    //快速切换到自身的按钮

    [m_waitSendBut setBackgroundImage:m_btnImageNormal forState:UIControlStateNormal];
    [m_waitSendBut setBackgroundImage:m_btnImagePress forState:UIControlStateHighlighted];
    
    [m_waitSendBut addTarget:self action:@selector(onWaitSend) forControlEvents:UIControlEventTouchUpInside];
    
    //待批／正批箱
    m_waitEvaluteBut = [[UIButton alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
    [m_waitEvaluteBut setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [m_waitEvaluteBut setTitle:@"       待批箱" forState:UIControlStateNormal];
    
    //快速切换到自身的按钮
    [m_waitEvaluteBut setBackgroundImage:m_btnImageNormal forState:UIControlStateNormal];
    [m_waitEvaluteBut setBackgroundImage:m_btnImagePress forState:UIControlStateHighlighted];
    
    [m_waitEvaluteBut addTarget:self action:@selector(onWaitEvalute) forControlEvents:UIControlEventTouchUpInside];
    
    //退回箱
    m_withDrawalBut = [[UIButton alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
    [m_withDrawalBut setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [m_withDrawalBut setTitle:@"       退回箱" forState:UIControlStateNormal];
    //快速切换到自身的按钮
    
    [m_withDrawalBut setBackgroundImage:m_btnImageNormal forState:UIControlStateNormal];
    [m_withDrawalBut setBackgroundImage:m_btnImagePress forState:UIControlStateHighlighted];
    
    [m_withDrawalBut addTarget:self action:@selector(onWithDrawl) forControlEvents:UIControlEventTouchUpInside];
    
    //已经发送箱
    m_haveSendedNum = [[UILabel alloc] initWithFrame:CGRectMake(8.0, 2.0, 18.0, 18.0)];
    m_haveSendedNum.font = [UIFont systemFontOfSize:12];
    [m_haveSendedNum setBackgroundColor:[UIColor  clearColor]];
    m_haveSendedNum.textColor = [UIColor whiteColor];
    [m_haveSendedNum setText:@"12"];
    
    m_haveSendedBut = [[UIButton alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
    [m_haveSendedBut setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [m_haveSendedBut setTitle:@" 已发箱" forState:UIControlStateNormal];
    //快速切换到自身的按钮
 
    [m_haveSendedBut setBackgroundImage:m_btnImageNormal forState:UIControlStateNormal];
    [m_haveSendedBut setBackgroundImage:m_btnImagePress forState:UIControlStateHighlighted];
    
    [m_haveSendedBut addTarget:self action:@selector(onHaveSended) forControlEvents:UIControlEventTouchUpInside];
    
    //草稿箱
    m_draftMailNum = [[UILabel alloc] initWithFrame:CGRectMake(8.0, 2.0, 18.0, 18.0)];
    m_draftMailNum.font = [UIFont systemFontOfSize:12];
    [m_draftMailNum setBackgroundColor:[UIColor  clearColor]];
    m_draftMailNum.textColor = [UIColor whiteColor];
    [m_draftMailNum setText:@"12"];
    
    m_draftBut = [[UIButton alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
    [m_draftBut setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [m_draftBut setTitle:@" 草稿箱" forState:UIControlStateNormal];
    //快速切换到自身的按钮
    [m_draftBut setBackgroundImage:m_btnImageNormal forState:UIControlStateNormal];
    [m_draftBut setBackgroundImage:m_btnImagePress forState:UIControlStateHighlighted];
    //[switchBtnImagePressed release];
    
    [m_draftBut addTarget:self action:@selector(onDraft) forControlEvents:UIControlEventTouchUpInside];
    
    //垃圾箱
    m_trashBut = [[UIButton alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
    [m_trashBut setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [m_trashBut setTitle:@" 垃圾箱" forState:UIControlStateNormal];
    //快速切换到自身的按钮
    [m_trashBut setBackgroundImage:m_btnImageNormal forState:UIControlStateNormal];
    [m_trashBut setBackgroundImage:m_btnImagePress forState:UIControlStateHighlighted];
    //[switchBtnImagePressed release];
    
    [m_trashBut addTarget:self action:@selector(onTrash) forControlEvents:UIControlEventTouchUpInside];
    
    //回收箱
    m_recycleBut = [[UIButton alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
    [m_recycleBut setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [m_recycleBut setTitle:@" 回收箱" forState:UIControlStateNormal];
    
    //快速切换到自身的按钮
    [m_recycleBut setBackgroundImage:m_btnImageNormal forState:UIControlStateNormal];
    [m_recycleBut setBackgroundImage:m_btnImagePress forState:UIControlStateHighlighted];
    
    [m_recycleBut addTarget:self action:@selector(onRecycle) forControlEvents:UIControlEventTouchUpInside];
    
    //已删除箱
    m_deletedBut = [[UIButton alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
    [m_deletedBut setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [m_deletedBut setTitle:@" 已删除" forState:UIControlStateNormal];
    //快速切换到自身的按钮
    [m_deletedBut setBackgroundImage:m_btnImageNormal forState:UIControlStateNormal];
    [m_deletedBut setBackgroundImage:m_btnImagePress forState:UIControlStateHighlighted];    
    [m_deletedBut addTarget:self action:@selector(onDelete) forControlEvents:UIControlEventTouchUpInside];
    /************************************************************************/
    
    //员工id
    m_strEmployeeID = [[NSString alloc]initWithFormat:@"%@", [[Session share] getMemberID]];
   

}
//******************************************************
// Method:     viewDidUnload
// Access:     public 
// Returns:    void
// Parameter:  
// Note:	   
// Author      muzongcun  2012/03/12 create
//*******************************************************
- (void)viewDidUnload 
{
    [super viewDidUnload];
}

//******************************************************
// Method:     dealloc
// Access:     public 
// Returns:    void
// Parameter:  
// Note:	   
// Author      muzongcun  2012/03/12 create
//*******************************************************
- (void)dealloc 
{
    [m_stafferSwitchBut release];   //业务员切换按钮
    [m_clientSwitchBut release];    //客户切换按钮
    [m_receiveBut release];         //接收箱
    [m_sendBut release];            //发送箱
    [m_haveSendedBut release];      //已发送箱
    [m_draftBut release];           //草稿箱
    [m_trashBut release];           //垃圾箱
    [m_recycleBut release];         //回收箱
    [m_deletedBut release];         //回收箱
    [m_mailStafferList release];
    [m_mailClientList release];
    [super dealloc];
}

#pragma mark - Public

//******************************************************
// Method:     setVisible
// Access:     public 
// Returns:    void
// Parameter:  BOOL
// Note:	   
// Author      muzongcun  2012/03/12 create
//*******************************************************
- (void)setVisible:(BOOL)visible 
{
    self.view.hidden = !visible;
}

#pragma mark - UITableView delegate

//******************************************************
// Method:     tableView
// Access:     public 
// Returns:    void
// Parameter:  BOOL
// Note:	   Called after the user changes the selection.
// Author      muzongcun  2012/03/12 create
//*******************************************************

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
    switch (indexPath.row) 
    {
        case 0:
        {
//            if(!m_mailStafferList)
//            {
//                
//                m_mailStafferList = [[MailStafferList alloc] initWithNibName:@"MailStafferList" bundle:nil];
//                m_mailStafferList.stafferDelegate = self;
//                
//            }
//            [self.parentViewController presentModalViewController:m_mailStafferList animated:YES];
        }
        break;
        case 1:
        {
#ifdef _text
            if(!m_mailClientList)
            {
                m_mailClientList = [[MailClientList alloc] initWithNibName:@"MailClientList" bundle:nil];
                m_mailClientList.m_clientDelegate = self;
                
            }
            [self.parentViewController presentModalViewController:m_mailClientList animated:YES];
#endif
        }
            break;
        case 2:
            break;
        case 3:
            break;
        case 4:
            break;
        case 5:
            break;
        case 6:
            break;
        default:
            break;
    }
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

//******************************************************
// Method:     menuAnimationEnd
// Access:     public 
// Returns:    void
// Parameter:  BOOL
// Note:	   
// Author      muzongcun  2012/03/12 create
//*******************************************************
- (void) menuAnimationEnd 
{
    [m_nav menuShown: m_menuShown];
}

#pragma mark - UITableView datasource
//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
//{
//    // Return the number of sections.
//    return 1;
//}
//******************************************************
// Method:     tableView
// Access:     public 
// Returns:    void
// Parameter:  section
// Parameter:  tableView
// Note:	   
// Author      muzongcun  2012/03/12 create
//*******************************************************
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{
   return 12;
}

//******************************************************
// Method:     tableView
// Access:     public 
// Returns:    void
// Parameter:  tableView
// Parameter:  indexPath
// Note:	   
// Author      muzongcun  2012/03/12 create
//*******************************************************
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.row) 
    {
        case 0:
        {
            return 44;
        }
        case 1:
        {
            return 44;
        }
//        case 2:
//        {
//           if ([[Session share] getPermission] == NO && m_bStafferClient)  
//            {
//                return 0;
//            }
//            break;
//        }
        case 4:
        {
            if (!m_bStafferClient) 
            {
                return 0;
            } 
            if (!m_bStretch) 
            {
                return 0;  
            } 
            break;
        }
        case 5:
        {
            if (!m_bStafferClient) 
            {
                return 0;
            } 
            if (!m_bStretch) 
            {
                return 0;  
            } 
            break;
        }
        case 6:
        {
            if (!m_bStafferClient) 
            {
                return 0;
            } 
            if (!m_bStretch) 
            {
                return 0;  
            } 
            break;
        }
        case 7:
        {
            if (!m_bStafferClient) 
            {
                return 0;
            } 
            break;
        }
        case 8:
        {
            if (!m_bStafferClient) 
            {
                return 0;
            } 
            break;
        }
        case 9:
        {
            if (!m_bStafferClient) 
            {
                return 0;
            } 
            break;
        }
        case 10:
        {
            if (!m_bStafferClient) 
            {
                return 0;
            } 
            break;
        }
        case 11:
        {
            if (!m_bStafferClient) 
            {
               return 0;
            } 
            break;
        }

        default:
            break;
    }
    return 44;
}

//******************************************************
// Method:     tableView
// Access:     public 
// Returns:    void
// Parameter:  tableView
// Parameter:  indexPath
// Note:	   
// Author      muzongcun  2012/03/12 create
//*******************************************************
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    static NSString *CellIdentifier = @"MainViewTableCell";
	UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if (cell == nil) 
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
	}
    //在cellview中添加背景
    [tableView setBackgroundColor:[UIColor colorWithRed:30/255.0 green:30/255.0 blue:30/255.0 alpha:1.0]];
    
    cell.textLabel.textColor = [UIColor whiteColor];
    if (indexPath.section == 0) 
    {
        switch (indexPath.row) 
        {
            case 0:
            {
                [self SetTabImage:m_bStafferClient];
            
                [m_stafferSwitchBut removeFromSuperview];
                [m_clientSwitchBut removeFromSuperview];

                [cell addSubview:m_stafferSwitchBut];
                [cell addSubview:m_clientSwitchBut];
                
                break;
            }
            case 1:
            {
                
                [m_stafferNameTitle removeFromSuperview];
                [m_switchBut addSubview: m_stafferNameTitle];
                
                [m_stafferName removeFromSuperview];
                [m_switchBut addSubview: m_stafferName];
                
                [m_stafferClientSwitchBut removeFromSuperview];
                
                [m_switchBut addSubview: m_stafferClientSwitchBut];
                
                //如果是客户的情况下，变成发件箱
                if (m_bStafferClient && [[Session share] getPermission] == NO) 
                {
                    m_stafferClientSwitchBut.hidden = YES;
                }
                else
                {
                    m_stafferClientSwitchBut.hidden = NO;
                }
                
                [m_switchBut removeFromSuperview];
                [cell addSubview: m_switchBut];
                break;
            }

            case 2:
            {
                [m_receiveMailNum removeFromSuperview];
                //[m_sendMailNumImageView addSubview:m_receiveMailNum];
                
                [m_receiveBut removeFromSuperview];
                
                //[m_receiveBut addSubview:m_sendMailNumImageView];
                [m_receiveBut addSubview:m_receiveMailNum];
                
                //m_receiveMailNum.superview.hidden = YES;
                [cell addSubview: m_receiveBut];
                
                break;
            }
            case 3:
            {
                
#ifdef _test
                //移除前一次添加的view
                for (UIView * view in m_sendBut.subviews) 
                {
                    if ([view isKindOfClass:[UIImageView class]]) 
                    {
                        [view removeFromSuperview];
                    }
                }
                [m_clientSendBut removeFromSuperview];
                [m_sendBut removeFromSuperview];
                
                //如果是客户的情况下，变成发件箱
                if (!m_bStafferClient) 
                {
                    [cell addSubview: m_clientSendBut];
                    break;
                }
                
                //如果是业务员的情况下，选择树型控件
                UIImageView* mailTreeImageView = nil;
                if (m_bStretch) 
                {
                    mailTreeImageView = m_mailTreeImageViewNormal;
                }
                else
                {
                    mailTreeImageView = m_mailTreeImageViewPress;
                }
                
               // [cell addSubview: m_ImageView];
                [m_sendBut addSubview:mailTreeImageView];
                [cell addSubview: m_sendBut];
#endif
                //移除前一次添加的view
                [m_clientSendBut removeFromSuperview];
                [m_sendBut removeFromSuperview];
                
                //如果是客户的情况下，变成发件箱
                if (!m_bStafferClient) 
                {
                    [cell addSubview: m_clientSendBut];
                    break;
                }
                [m_sendBut addSubview:m_mailTreeImageViewNormal];
                [m_sendBut addSubview:m_mailTreeImageViewPress];
              
                //如果是业务员的情况下，选择树型控件
                if (m_bStretch) 
                {
                    [m_mailTreeImageViewPress removeFromSuperview];
                    
                }
                else
                {
                    [m_mailTreeImageViewNormal removeFromSuperview];
                }
                [cell addSubview: m_sendBut]; 
                break;
            }
            case 4:
            {
                if (!m_bStretch ||!m_bStafferClient) 
                {
                    [m_waitSendAngleArrowView removeFromSuperview];
                    [m_waitSendBut removeFromSuperview];
                    cell.hidden = YES;
                    break;  
                } 
                [m_waitSendAngleArrowView removeFromSuperview];
                [m_waitSendBut removeFromSuperview];
                [m_waitSendBut addSubview:m_waitSendAngleArrowView];
                [cell addSubview: m_waitSendBut];
                
                break;
            }
            case 5:
            {
                if (!m_bStretch ||!m_bStafferClient) 
                {
                    [m_waitEvaluteAngleArrowView removeFromSuperview];
                    [m_waitEvaluteBut removeFromSuperview];
                    cell.hidden = YES;
                    break;  
                } 
                [m_waitEvaluteAngleArrowView removeFromSuperview];
                [m_waitEvaluteBut removeFromSuperview];
                [m_waitEvaluteBut addSubview: m_waitEvaluteAngleArrowView];
                [cell addSubview: m_waitEvaluteBut];
                break;
            }
            case 6:
            {
                if (!m_bStretch ||!m_bStafferClient) 
                {
                    [m_withdrawAngleArrowView removeFromSuperview];
                    [m_withDrawalBut removeFromSuperview];
                    cell.hidden = YES;
                    break;  
                } 
                [m_withdrawAngleArrowView removeFromSuperview];
                [m_withDrawalBut removeFromSuperview];
                [m_withDrawalBut addSubview: m_withdrawAngleArrowView];
                [cell addSubview: m_withDrawalBut];
                break;
            }
                
            case 7:
            {
                if (!m_bStafferClient) 
                {
                    cell.hidden = YES;
                    break;
                } 
                [m_haveSendedBut removeFromSuperview];
                [cell addSubview: m_haveSendedBut];
                break;
            }
                
            case 8:
            {
                if (!m_bStafferClient) 
                {
                    cell.hidden = YES;
                    break;
                } 
                
                [m_draftBut removeFromSuperview];
                [cell addSubview: m_draftBut];
                break;
            }
            case 9:
            {
                if (!m_bStafferClient) 
                {
                    cell.hidden = YES;
                    break;
                } 
                
                [m_trashBut removeFromSuperview];
                [cell addSubview: m_trashBut];
                break;
            }
            case 10:
            {
                if (!m_bStafferClient) 
                {
                    cell.hidden = YES;
                    break;
                } 

                [m_recycleBut removeFromSuperview];
                [cell addSubview: m_recycleBut];
                break;
            }
            case 11:
            {
                
                if (!m_bStafferClient || [[Session share] getPermission] == NO) 
                {
                    cell.hidden = YES;
                    break;
                } 
                
                [m_deletedBut removeFromSuperview];
                [cell addSubview: m_deletedBut];
                break;
            }
            default:
                break;
        }
    }
    
	return cell;
}

//******************************************************
// Method:     fingerHonMoved
// Access:     public 
// Returns:    void
// Parameter:  distance
// Note:	   
// Author      muzongcun  2012/03/12 create
//*******************************************************
- (void) fingerHonMoved: (float) distance 
{
    [UIView beginAnimations: nil context:nil];
    [UIView setAnimationDuration: 0.3];
    CGRect newContentVCFrame = m_contentBaseFrame;
    newContentVCFrame.origin.x += distance;
    if (newContentVCFrame.origin.x < 0) 
    {
        newContentVCFrame.origin.x = 0;
    } 
    else if (newContentVCFrame.origin.x > 290) 
    {
        newContentVCFrame.origin.x = 290;
    }
    m_nav.view.frame = newContentVCFrame;
    [UIView commitAnimations];     
}

#pragma mark-- NavigationViewControllerDelegate methods 
//******************************************************
// Method:     showMenu
// Access:     public 
// Returns:    void
// Parameter:  BOOL
// Note:	   
// Author      muzongcun  2012/03/12 create
//*******************************************************
- (void) showMenu: (BOOL) show 
{
    [UIView beginAnimations: nil context:nil];
    [UIView setAnimationDuration: 0.3];
    [UIView setAnimationDelegate: self];
    [UIView setAnimationDidStopSelector: @selector(menuAnimationEnd)];
    CGRect newContentVCFrame = m_contentBaseFrame;
    if (show) 
    {
        newContentVCFrame.origin.x = MenuWidth;
    } 
    else 
    {
        newContentVCFrame.origin.x = 0;        
    }
    m_nav.view.frame = newContentVCFrame;
    [UIView commitAnimations]; 
}
//******************************************************
// Method:     chickSplitHalfView
// Access:     public 
// Returns:    void
// Parameter:  id
// Note:	   切换为半屏view
// Author      muzongcun  2012/03/12 create
//*******************************************************
//
- (void) chickSplitHalfView 
{
    [self showMenu: YES];
    m_menuShown = YES;
}

//******************************************************
// Method:     endTouch
// Access:     public 
// Returns:    void
// Parameter:  id
// Note:	   用户touch
// Author      muzongcun  2012/03/12 create
//*******************************************************
- (void) endTouch 

{
    if (m_nav.view.frame.origin.x > m_nav.view.frame.size.width/2) 
    {
        [self showMenu: YES];
        m_menuShown = YES;
    } 
    else 
    {
        [self showMenu: NO];
        m_menuShown = NO;
    }
    //contentBaseFrame = nav.view.frame;
}

//******************************************************
// Method:     switchMotion
// Access:     public 
// Returns:    void
// Parameter:  id
// Note:	   切换半屏和全凭
// Author      muzongcun  2012/03/12 create
//*******************************************************
- (void) switchMotion 
{
    m_menuShown = !m_menuShown;
    [self showMenu: m_menuShown];
    //contentBaseFrame = nav.view.frame;
}

#pragma mark -staffer or client List
-(NSString*) GetEmployeeID
{
    NSString* employeeID =  m_strEmployeeID;
    return employeeID;
}
//******************************************************
// Method:     SelectClientName
// Access:     public 
// Returns:    void
// Parameter:  id
// Note:	   返回选择的客户的名字
// Author      muzongcun  2012/03/12 create
//*******************************************************
-(void)SelectClientName:(id)obj
{
    //选择的客户id
    m_mailList.m_selectClientID = [obj objectForKey:@"id"];
    
    NSString* strClientName = [obj objectForKey:@"customer_name_cn"];
    m_stafferClientInfo  = [[NSString alloc] initWithString:[NSString stringWithFormat:@"%@:%@",@"客户",strClientName]];
    m_stafferName.text = strClientName;
    
    m_ClientSwittchID   = [obj objectForKey:@"id"];  
    m_ClientSwittchName = strClientName; 
    
    [self dismissModalViewControllerAnimated:YES];
}

//******************************************************
// Method:     SelectStafferName
// Access:     public 
// Returns:    void
// Parameter:  id
// Note:	   返回选择的员工名字
// Author      muzongcun  2012/03/12 create
//*******************************************************
-(void)SelectStafferName:(id)obj
{
    m_strEmployeeID = [[NSString alloc]initWithString:[obj objectForKey:@"id"]];
    
    //设置获取邮箱的业务员id
    m_mailList.m_employeeID  = m_strEmployeeID;
    NSString* strStafferName = [obj objectForKey:@"user_name_cn"];
    m_stafferClientInfo      = [[NSString alloc] initWithString:[NSString stringWithFormat:@"%@:%@",@"业务员",strStafferName]];

    m_postionName           = [[NSString alloc]initWithString: @"业务员"];
    m_stafferName.text      =  strStafferName;
    m_stafferNameTitle.text =  m_postionName;
    m_stafferSwitchID       =  [obj objectForKey:@"id"];  
    
    NSLog(@"m_strEmployeeID = %@,strStafferName=%@",m_strEmployeeID,strStafferName);
    
    m_stafferSwitchName     =  strStafferName; 
    
    [self dismissModalViewControllerAnimated:YES];
}
#pragma mark--
#pragma mark ------主navigation单击事件处理button-------
#pragma mark--
//******************************************************
// Method:     onSwitchOneSelf
// Access:     public 
// Returns:    void
// Parameter:  
// Note:	   快速切换到自己
// Author      muzongcun  2012/03/12 create
//*******************************************************
-(void) onSwitchOneSelf
{
    if (m_bStafferClient == NO) 
    {
        [self onStafferTabSwitch];
    }
    m_stafferNameTitle.text =  [[Session share] getMemberPosiName];
    m_stafferName.text      =  [[Session share] getMemberNickName];
    m_mailList.m_employeeID =  [[Session share] getMemberID];
    m_postionName           =  [[Session share] getMemberPosiName];
    m_stafferSwitchName     =  [[Session share] getMemberNickName];
    
    [m_mailList refreshData];
}

//******************************************************
// Method:     SetAllButImage
// Access:     public 
// Returns:    void
// Parameter:  void
// Note:	   设置所有按钮的图片
// Author      muzongcun  2012/03/12 create
//*******************************************************
- (void) SetAllButImage
{
    //隐藏邮件数量
    [m_receiveMailNum setHidden:YES];
    //清除前一次的的数据
    [m_mailList.m_mutableArray removeAllObjects];
    [m_mailList.m_importantArray removeAllObjects];
    [m_mailList.m_checkedArray removeAllObjects];
    m_mailList.m_toolDrawerView.hidden = YES;
    
    //设置为非搜索的状态
    m_mailList.m_bIsSearching = NO;
    //快速切换到自身的按钮
    UIImage *switchBtnImageNormal = [UIImage imageNamed:PIC_MAIL_MENU_NORMAL];
    [m_receiveBut setBackgroundImage:switchBtnImageNormal forState:UIControlStateNormal];
    [m_clientSendBut setBackgroundImage:switchBtnImageNormal forState:UIControlStateNormal];
    [m_waitSendBut setBackgroundImage:switchBtnImageNormal forState:UIControlStateNormal];
    [m_waitEvaluteBut setBackgroundImage:switchBtnImageNormal forState:UIControlStateNormal];
    [m_withDrawalBut setBackgroundImage:switchBtnImageNormal forState:UIControlStateNormal];
    [m_haveSendedBut setBackgroundImage:switchBtnImageNormal forState:UIControlStateNormal];
    [m_draftBut setBackgroundImage:switchBtnImageNormal forState:UIControlStateNormal];
    [m_trashBut setBackgroundImage:switchBtnImageNormal forState:UIControlStateNormal];
    [m_recycleBut setBackgroundImage:switchBtnImageNormal forState:UIControlStateNormal];
    [m_deletedBut setBackgroundImage:switchBtnImageNormal forState:UIControlStateNormal];
    //[switchBtnImageNormal release];
}

//******************************************************
// Method:     SetTabImage
// Access:     public 
// Returns:    void
// Parameter:  void
// Note:	   设置选中的tab图片
// Author      muzongcun  2012/03/12 create
//*******************************************************
- (void) SetTabImage:(BOOL) bIsTab
{
    if (m_stafferSwitchBut == nil || m_clientSwitchBut == nil) 
    {
        return;
    }
    //背景图片设置
    UIImage *tabNormal = [UIImage imageNamed:PIC_MAIL_SWITCH_TAB_NORMAL];
    UIImage *tabClientPressed = [UIImage imageNamed:PIC_MAIL_SWITCH_TAB_CLIENT_PRESS];
    UIImage *tabStafferPressed = [UIImage imageNamed:PIC_MAIL_SWITCH_TAB_STAFFER_PRESS];
    if (!bIsTab) 
    {
        [m_stafferSwitchBut setBackgroundImage:tabNormal forState:UIControlStateNormal];
        [m_clientSwitchBut setBackgroundImage:tabClientPressed forState:UIControlStateNormal];
    }else
    {

        [m_stafferSwitchBut setBackgroundImage:tabStafferPressed forState:UIControlStateNormal];
        [m_clientSwitchBut setBackgroundImage:tabNormal forState:UIControlStateNormal];
    }
}

//******************************************************
// Method:     onStafferSwitch
// Access:     public 
// Returns:    void
// Parameter:  void
// Note:	   员工切换
// Author      muzongcun  2012/03/12 create
//*******************************************************
- (void) onStafferSwitch
{
    if(!m_mailStafferList)
    {
        
        m_mailStafferList = [[MailStafferList alloc] initWithNibName:@"MailStafferList" bundle:nil];
        m_mailStafferList.stafferDelegate = self;
    }
    [self.parentViewController presentModalViewController:m_mailStafferList animated:YES];
}

//******************************************************
// Method:     onClientSwitch
// Access:     public 
// Returns:    void
// Parameter:  void
// Note:	   客户切换
// Author      muzongcun  2012/03/12 create
//*******************************************************
- (void) onClientSwitch
{
    m_mailClientList = [[MailClientList alloc]initWithNibName:@"MailClientList" navMainViewCtl:self bundle:nil];
    m_mailClientList.m_clientDelegate = self;
    [self.parentViewController presentModalViewController:m_mailClientList animated:YES];
}
- (void) onStafferClientSwitch
{
    if (m_bStafferClient == NO) 
    {
        [self onClientSwitch];
    }else
    {
        [self onStafferSwitch];
    }
}
//******************************************************
// Method:     onStafferTabSwitch
// Access:     public 
// Returns:    void
// Parameter:  void
// Note:	   tab员工切换
// Author      muzongcun  2012/03/12 create
//*******************************************************
- (void) onStafferTabSwitch
{

    if (m_bStafferClient == NO) 
    {
        m_stafferName.text      =  m_stafferSwitchName;
        m_stafferNameTitle.text =  m_postionName; 
        m_bStafferClient        =  YES;
        [self SetTabImage:YES];
        
        //设置文字颜色
        [m_stafferSwitchBut setTitleColor:[UIColor colorWithRed:56/255.0 green:191/255.0 blue:255/255.0 alpha:1.0] forState:UIControlStateNormal]; 
        [m_clientSwitchBut setTitleColor:[UIColor colorWithRed:1 green:1 blue:1 alpha:1.0] forState:UIControlStateNormal]; 
        [m_receiveMailNum setHidden:YES];
        
        [m_mailList refreshData];
        
        //刷新navigationmainview
        [m_tableView reloadData];
    }
}

//******************************************************
// Method:     onClientTabSwitch
// Access:     public 
// Returns:    void
// Parameter:  void
// Note:	   tab客户切换
// Author      muzongcun  2012/03/12 create
//*******************************************************
- (void) onClientTabSwitch
{
    if (m_bStafferClient == YES) 
    {
        m_stafferNameTitle.text = @"客户";
        m_stafferName.text = m_ClientSwittchName;
        m_bStafferClient = NO;
        [self SetTabImage:NO];
        [m_clientSwitchBut setTitleColor:[UIColor colorWithRed:56/255.0 green:191/255.0 blue:255/255.0 alpha:1.0] forState:UIControlStateNormal]; 
        [m_stafferSwitchBut setTitleColor:[UIColor colorWithRed:1 green:1 blue:1 alpha:1.0] forState:UIControlStateNormal]; 
        
        [m_receiveMailNum setHidden:YES];
        
        [m_mailList refreshData];
        
        //刷新navigationmainview
        [m_tableView reloadData];
    }
}

//******************************************************
// Method:     onReceive
// Access:     public 
// Returns:    void
// Parameter:  void
// Note:	   接收箱
// Author      muzongcun  2012/03/12 create
//*******************************************************
- (void) onReceive
{
    //设置maillist的标题
    m_mailList.m_barTitleLabel.text = @"收件箱";
    m_boxType = RECEIVE_BOX;
    [self SetAllButImage];
    UIImage *switchBtnImageNormal = [UIImage imageNamed:PIC_MAIL_MENU_PRESS];
    [m_receiveBut setBackgroundImage:switchBtnImageNormal forState:UIControlStateNormal];
    //[switchBtnImageNormal release];
    //刷新maillist数据
    //从服务器取得接收未读的邮件
//    XmlRpc *xml = [[XmlRpc alloc] init];
//    int boxNum = [xml getMailByBoxCountNoRead:m_mailList.m_employeeID boxType:@"01"]; 
//    NSString * strBoxNum = [NSString stringWithFormat:@"%i",boxNum];
//    if (boxNum > 0) 
//    {
//        [m_receiveMailNum.superview setHidden:NO];
//        [m_receiveMailNum setText:strBoxNum];
//    }
//    else
//    {
//        [m_receiveMailNum.superview setHidden:YES];
//    }
//    [xml release];
    
    [m_mailList refreshData];
    
}

//******************************************************
// Method:     onHaveSended
// Access:     public 
// Returns:    void
// Parameter:  void
// Note:	   已经发送箱
// Author      muzongcun  2012/03/12 create
//*******************************************************
- (void) onHaveSended
{
    //设置maillist的标题
    m_mailList.m_barTitleLabel.text = @"已发件箱";
    
    m_boxType = HAVE_SENDED_BOX;
    [self SetAllButImage];
    UIImage *switchBtnImageNormal = [UIImage imageNamed:PIC_MAIL_MENU_PRESS];
    [m_haveSendedBut setBackgroundImage:switchBtnImageNormal forState:UIControlStateNormal];
    //[switchBtnImageNormal release];
    //刷新maillist数据
    [m_mailList refreshData];
}

//******************************************************
// Method:     onSend
// Access:     public 
// Returns:    void
// Parameter:  void
// Note:	   发送箱
// Author      muzongcun  2012/03/12 create
//*******************************************************
- (void) onSend
{
    m_bStretch = !m_bStretch;

//    for (UIView * view in m_sendBut.subviews) 
//    {
//        if ([view isKindOfClass:[UIImageView class]]) 
//        {
//            [view removeFromSuperview];
//        }
//    }
    [m_tableView reloadData];
}

//******************************************************
// Method:     onClientSend
// Access:     public 
// Returns:    void
// Parameter:  void
// Note:	   客户发送箱
// Author      muzongcun  2012/03/12 create
//*******************************************************
- (void) onClientSend
{
    //设置maillist的标题
    m_mailList.m_barTitleLabel.text = @"待发箱";
    
    m_boxType = SEND_BOX;
    [self SetAllButImage];
    UIImage *switchBtnImageNormal = [UIImage imageNamed:PIC_MAIL_MENU_PRESS];
    [m_clientSendBut setBackgroundImage:switchBtnImageNormal forState:UIControlStateNormal];
    //[switchBtnImageNormal release];
    //刷新maillist数据
    [m_mailList refreshData];
}

//******************************************************
// Method:     onWaitSend
// Access:     public 
// Returns:    void
// Parameter:  void
// Note:	   待发箱
// Author      muzongcun  2012/03/12 create
//*******************************************************
- (void) onWaitSend
{
    //设置maillist的标题
    m_mailList.m_barTitleLabel.text = @"待发箱";
    
    m_boxType = WAIT_SEND_BOX;
    [self SetAllButImage];
    UIImage *switchBtnImageNormal = [UIImage imageNamed:PIC_MAIL_MENU_PRESS];
    [m_waitSendBut setBackgroundImage:switchBtnImageNormal forState:UIControlStateNormal];
    //[switchBtnImageNormal release];
    //刷新maillist数据
    [m_mailList refreshData];
    
}

//******************************************************
// Method:     onWaitEvalute
// Access:     public 
// Returns:    void
// Parameter:  void
// Note:	   待批／正批箱
// Author      muzongcun  2012/03/12 create
//*******************************************************
- (void) onWaitEvalute
{
    //设置maillist的标题
    m_mailList.m_barTitleLabel.text = @"待批箱";
    
    m_boxType = WAIT_EVALUTE_BOX;
    [self SetAllButImage];
    UIImage *switchBtnImageNormal = [UIImage imageNamed:PIC_MAIL_MENU_PRESS];
    [m_waitEvaluteBut setBackgroundImage:switchBtnImageNormal forState:UIControlStateNormal];
    //[switchBtnImageNormal release];
    //刷新maillist数据
    [m_mailList refreshData];
    
}

//******************************************************
// Method:     onWithDrawl
// Access:     public 
// Returns:    void
// Parameter:  void
// Note:	   退回箱
// Author      muzongcun  2012/03/12 create
//*******************************************************
- (void) onWithDrawl
{
    //设置maillist的标题
    m_mailList.m_barTitleLabel.text = @"退回箱";
    
    m_boxType = WITHDRAWL_BOX;
    [self SetAllButImage];
    UIImage *switchBtnImageNormal = [UIImage imageNamed:PIC_MAIL_MENU_PRESS];
    [m_withDrawalBut setBackgroundImage:switchBtnImageNormal forState:UIControlStateNormal];
    //[switchBtnImageNormal release];
    //刷新maillist数据
    [m_mailList refreshData];
}
//******************************************************
// Method:     onDraft
// Access:     public 
// Returns:    void
// Parameter:  void
// Note:	   草稿箱
// Author      muzongcun  2012/03/12 create
//*******************************************************
- (void) onDraft
{
    //设置maillist的标题
    m_mailList.m_barTitleLabel.text = @"草稿箱";

    m_boxType = DRAFT_BOX;
    [self SetAllButImage];
    UIImage *switchBtnImageNormal = [UIImage imageNamed:PIC_MAIL_MENU_PRESS];
    [m_draftBut setBackgroundImage:switchBtnImageNormal forState:UIControlStateNormal];
    //[switchBtnImageNormal release];
    //刷新maillist数据
    [m_mailList refreshData];
}

//******************************************************
// Method:     onTrash
// Access:     public 
// Returns:    void
// Parameter:  void
// Note:	   垃圾箱
// Author      muzongcun  2012/03/12 create
//*******************************************************
- (void) onTrash
{
    //设置maillist的标题
    m_mailList.m_barTitleLabel.text = @"垃圾箱";
    
     m_boxType = TRASH_BOX;
    [self SetAllButImage];
    UIImage *switchBtnImageNormal = [UIImage imageNamed:PIC_MAIL_MENU_PRESS];
    [m_trashBut setBackgroundImage:switchBtnImageNormal forState:UIControlStateNormal];
    //[switchBtnImageNormal release];
    //刷新maillist数据
    [m_mailList refreshData];
    
}

//******************************************************
// Method:     onRecyle
// Access:     public 
// Returns:    void
// Parameter:  void
// Note:	   回收箱
// Author      muzongcun  2012/03/12 create
//*******************************************************
- (void) onRecycle
{
    //设置maillist的标题
    m_mailList.m_barTitleLabel.text = @"回收箱";
    
     m_boxType = RECYCLE_BOX;
    [self SetAllButImage];
    UIImage *switchBtnImageNormal = [UIImage imageNamed:PIC_MAIL_MENU_PRESS];
    [m_recycleBut setBackgroundImage:switchBtnImageNormal forState:UIControlStateNormal];
    //[switchBtnImageNormal release];
    //刷新maillist数据
    [m_mailList refreshData];
}

//******************************************************
// Method:     onDelete
// Access:     public 
// Returns:    void
// Parameter:  void
// Note:	   回收箱
// Author      muzongcun  2012/03/12 create
//*******************************************************
- (void) onDelete
{
    //设置maillist的标题
    m_mailList.m_barTitleLabel.text = @"已删邮箱";
    
    m_boxType = DELETED_BOX;
    [self SetAllButImage];
    UIImage *switchBtnImageNormal = [UIImage imageNamed:PIC_MAIL_MENU_PRESS];
    [m_deletedBut setBackgroundImage:switchBtnImageNormal forState:UIControlStateNormal];
    //[switchBtnImageNormal release];
    //刷新maillist数据
    [m_mailList refreshData];

}
@end
